<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <title>云丁助手</title>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, width=device-width, initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
</head>

<body>
    <div id="app"></div>
    <script>
        apiready = function () {
            var url = "widget://code/index.html";
            init();
            enter(url);
        }

        function init() { // 初始化配置

            // 设置状态栏样式
            api.setStatusBarStyle({
                style: "dark"
            });

            // 保持屏幕长亮
            api.setKeepScreenOn({
                keepOn: true
            });

            api.addEventListener(
                {
                    name: 'keyback'
                },
                function (ret, err) {
                    api.closeWidget({}); // 应用管理关闭指定widget，也可以关闭应用
                }
            );

            // 监听网络
            api.addEventListener({
                name: "offline"
            },
                function (ret, err) {
                    api.alert({
                        msg: "网络连接异常，请确保网络正常后，再重试。"
                    },
                        function (ret, err) { }
                    );
                }
            );

            // 云修复
            api.addEventListener({
                name: "smartupdatefinish"
            },
                function (ret, err) {
                    api.rebootApp();
                }
            );
        }

        function enter(url) { // 打开页面
            // 移除启动页
            api.removeLaunchView({
                animation: {
                    type: "fade",
                    duration: 400
                }
            });

            openWin({
                url: url,
                reload: true
            });
        }

        function openWin(data) {
            api.openFrame({
                name: 'index',
                url: data.url,
                pageParam: data.pageParam,
                animation: data.animation ? data.animation : null,
                allowEdit: !!data.allowEdit,
                slidBackEnabled: !!data.slidBackEnabled,
                reload: !!data.reload,
                bounces: !!data.bounces
            });
        }

        function getPageNameFromUrl(url) {
            return url.substring(url.lastIndexOf('/') + 1, url.length) + '';
        }
    </script>
</body>

</html>